﻿using System;
using System.Runtime.InteropServices;

namespace WindowsAPI.Hooks
{
    public class HookEventArgs : EventArgs
    {
        private readonly int f_Code;
        private readonly IntPtr f_wParams;
        private readonly IntPtr f_lParams;

        public int Code { get { return f_Code; } }
        public IntPtr wParams { get { return f_wParams; } }
        public IntPtr lParams { get { return f_lParams; } }

        public IntPtr Result { get; set; }
        public bool Interrupt { get; set; }

        public HookEventArgs(int Code, IntPtr wParams, IntPtr lParams)
        {
            f_Code = Code;
            f_wParams = wParams;
            f_lParams = lParams;
            Result = IntPtr.Zero;
            Interrupt = false;
        }

        protected HookEventArgs(HookEventArgs arg) : this(arg.f_Code, arg.f_wParams, arg.f_lParams) { }

        public T wObject<T>() { return (T)Marshal.PtrToStructure(f_wParams, typeof(T)); }

        public T lObject<T>() { return (T)Marshal.PtrToStructure(f_lParams, typeof(T)); }

        public override string ToString() { return string.Format("Hook event ({0}):{1}/{2}", Code, wParams, lParams); }
    }
}